open(BUFF,"/data2/bsi/RandD/Arraybased_RND/BRCA/SNP.txt") or die "SNP.txt no found\n";
open(LOC,"/data2/bsi/RandD/Arraybased_RND/BRCA/snploc.txt") or die "snploc.txt not found\n";
$line = <BUFF>;
$line = <LOC>;
$n=0;
while(<BUFF>)
{
	chomp($_);
	$line = <LOC>;
	chomp($line);
	@loc = split("\t",$line);
	@array = split("\t",$_);
	$snp = shift(@array);
	$_ = join("\t",@array);
	$count1 =($_ =~ s/2/2/g);
	$count2 =($_ =~ s/1/1/g);
	$count3 =($_ =~ s/0/0/g);
	#if($count1 >10 && $count2 >10 && $count3 >10 && $loc[1] <23)
	if($count1 >  $count3)
	{
		$count = $count3 + $count2;
	}
	else
	{
		$count = $count1 + $count2;
	}
	if($count > 12)
	{
		#print $snp."\n";
		$hash{$snp} =1;
		$n++;
	}
}
#open(BUFF,"new_PVAL.txt") or die "PVAL.txt not found\n";
#open(WRBUFF,">PVAL_removed_10_count") or die "PVAL_removed_10_count not found\n";
$file = $ARGV[0];
chomp($file);
open(BUFF,"/data2/bsi/RandD/Arraybased_RND/BRCA/results_permutation/$file") or die "PVAL.txt not found\n";
open(WRBUFF,">/data2/bsi/RandD/Arraybased_RND/BRCA/results_permutation_mafcutoff/$file") or die "PVAL_removed_10_count not found\n";
$line = <BUFF>;
print WRBUFF $line;
@array = ();
while(<BUFF>)
{
        chomp($_);
        $_ =~ s/"//g;
        @array = split("\t",$_);
        if(exists($hash{$array[0]}))
        {
                print WRBUFF $_."\n";
        }
}

